package edu.ucsd.cse222b.network;

import java.util.HashSet;
import java.util.List;
import java.util.Set;


import org.jgrapht.Graph;
import org.jgrapht.GraphPath;

public class CandidatePath implements GraphPath<NetNode, Link> {
	
	private DCNetwork network;
	
	private List<Link> links;
	
	private EndHost src;
	
	private EndHost dst;
	
	private double weight;
	
	private double capacity;
	
	public CandidatePath(DCNetwork network, EndHost src, EndHost dst, List<Link> links, double weight){
		this.network=network;
		this.src=src;
		this.dst=dst;
		this.links=links;
		this.weight=weight;
	}
	
	public double getCapacity(){
		capacity = Double.MAX_VALUE;
		if (links.isEmpty())
			return capacity;
		
		for(Link link : links){
			if(capacity > link.getAvailableBandwidth())
				capacity = link.getAvailableBandwidth();
		}
		return capacity;
	}
	
	public Set<NetNode> getNodes(){
		Set<NetNode> nodes = new HashSet<NetNode>();
		nodes.add(src);
		for(Link link : links){
			nodes.add(link.getDstNode());	
		}
		return nodes;
	}
	
	
	public String toString(){
		String pathString="";
		pathString+=src+"->";
		for(Link link : links){
			if(link.getDstNode()!=dst){
				pathString+=link.getDstNode()+"->";
			}else{
				pathString+=link.getDstNode();
			}
		}
		return pathString;
	}
	
	public List<Link> getLinks(){
		return links;
	}
	
	public NetNode getDstHost(){
		return dst;
	}
	
	public NetNode getSrcHost(){
		return src;
	}

	@Override
	public List<Link> getEdgeList() {
		return links;
	}

	@Override
	public NetNode getEndVertex() {
		return dst;
	}

	@Override
	public Graph<NetNode, Link> getGraph() {
		return network;
	}

	@Override
	public NetNode getStartVertex() {
		return src;
	}

	@Override
	public double getWeight() {
		return weight;
	}

}
